package cn.edu.scau.cmi.duzefeng.factory.viewers;
import cn.edu.scau.cmi.duzefeng.factory.model.*;
import cn.edu.scau.cmi.duzefeng.factory.model.InsuranceSimpleFactory.InsuranceType;

import java.net.URL;

	import java.util.HashSet;
	import java.util.ResourceBundle;
	import java.util.Set;

	import cn.edu.scau.cmi.duzefeng.factory.insurance.Insurance;
	import javafx.event.ActionEvent;
	import javafx.fxml.FXML;
	import javafx.fxml.Initializable;
	import javafx.scene.control.Button;
	import javafx.scene.control.TextField;
	import javafx.scene.control.TextArea;
	import javafx.scene.control.ChoiceBox;
	import javafx.beans.value.ChangeListener;
	import javafx.beans.value.ObservableValue;
	
	
	public class MySimpleFactoryController implements Initializable {

	   @FXML
	   private TextArea outputTextField;
	   	   
	   @FXML
	   private Button createButton;

	   @FXML
	   private ChoiceBox <Insurance>insuranceBox;
	   
	   @Override
	   public void initialize(URL location, ResourceBundle resources) {
		   insuranceBox.getItems().addAll(InsuranceSimpleFactory.create(InsuranceType.CarDamage),
					InsuranceSimpleFactory.create(InsuranceType.DriversDamage),
					InsuranceSimpleFactory.create(InsuranceType.MultiDamage),
					InsuranceSimpleFactory.create(InsuranceType.SomebodyDie));
//		   	outputTextField.setWrapText(true);
			outputTextField.setEditable(false);
			insuranceBox.getSelectionModel().selectedIndexProperty().addListener(new ChangeListener<Number>() {
				@Override
				public void changed(ObservableValue<? extends Number> observable, Number oldValue, Number newValue) {
					outputTextField.setText(insuranceBox.getItems().get(newValue.intValue()).getName());
				}
			});
	   }
	}
